<template>
  <div class="dialog">
    <el-dialog
      :title="title"
      :visible.sync="visible"
      :close-on-click-modal="false"
      width="50%"
      top="20vh"
      @close="closeDialog"
    >
      <el-form
        :model="createForm"
        label-width="120px"
        label-suffix=":"
        class="searchw"
        ref="createForm"
        :rules="rule"
      >
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="车型名称" prop="vehicleModel">
              <el-input
                v-model.trim="createForm.vehicleModel"
                placeholder="请输入车型名称"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年份" prop="year">
              <el-date-picker
                v-model.trim="createForm.year"
                type="year"
                value-format="yyyy"
                format="yyyy"
                placeholder="选择年"
                :disabled="title == '车型详情'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="发动机" prop="engine">
              <el-input
                v-model.trim="createForm.engine"
                placeholder="请输入发动机"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排量" prop="displacement">
              <el-input
                v-model.trim="createForm.displacement"
                placeholder="请输入排量"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="前制动器" prop="frontBrake">
              <el-input
                v-model.trim="createForm.frontBrake"
                placeholder="请输入前制动器"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="后制动器" prop="rearBrake">
              <el-input
                v-model.trim="createForm.rearBrake"
                placeholder="请输入后制动器"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="车身形式" prop="bodyForm">
              <el-input
                v-model.trim="createForm.bodyForm"
                placeholder="请输入车身形式"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="驱动方式" prop="driveMethod">
              <el-input
                v-model.trim="createForm.driveMethod"
                placeholder="请输入驱动方式"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="驻车制动" prop="parkingBrake">
              <el-input
                v-model.trim="createForm.parkingBrake"
                placeholder="请输入驻车制动"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="功率" prop="power">
              <el-input
                v-model.trim="createForm.power"
                placeholder="请输入功率"
                :disabled="title == '车型详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" v-if="title != '新增车型'">
          <el-col :span="12">
            <el-form-item label="采集时间" prop="gatherTime">
              <el-input
                v-model.trim="createForm.gatherTime"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否采集" prop="gatherFlag">
              <el-input
                v-model.trim="createForm.gatherFlag"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">关 闭</el-button>
        <el-button
          type="primary"
          @click="confirmData('createForm')"
          v-if="title != '车型详情'"
          >保 存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'addBrand',
  props: {
    row: {
      type: Object,
      default: {}
    },
    title: {
      type: String,
      default: ''
    },
    value: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      visible: true,
      createForm: {
        vehicleModel: '',
        year: '',
        engine: '',
        displacement: '',
        frontBrake: '',
        rearBrake: '',
        bodyForm: '',
        driveMethod: '',
        parkingBrake: '',
        gatherTime: '',
        gatherFlag: ''
      },
       rule:{
        vehicleModel: [
          { required: true, message: '请输入车型名称', trigger: 'blur' },
        ],
        year:[
          { required: true, message: '请选择年份', trigger: 'change' },
        ],
        engine: [
          { required: true, message: '请输入发动机', trigger: 'blur' },
        ],
        displacement: [
          { required: true, message: '请输入排量', trigger: 'blur' },
        ],
        frontBrake: [
          { required: true, message: '请输入前制动器', trigger: 'blur' },
        ],
        rearBrake: [
          { required: true, message: '请输入后制动器', trigger: 'blur' },
        ],
        bodyForm: [
          { required: true, message: '请输入车身形式', trigger: 'blur' },
        ],
        driveMethod: [
          { required: true, message: '请输入驱动方式', trigger: 'blur' },
        ],
        parkingBrake: [
          { required: true, message: '请输入驻车制动', trigger: 'blur' },
        ],
      }
    }
  },
  created() {
    if(this.row.id){
      this.createForm = this.row
    }
  },
  mounted() {},
  methods: {
     confirmData(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid) {
          this.$emit('ok', this.createForm)
        }
      })
    },
    closeDialog() {
      this.$emit('cancle')
    }
  }
}
</script>
<style scoped lang="less">
.dialog {
  .el-date-editor.el-input {
    width: 100% !important;
  }
}
</style>
